package com.atguigu.gulimall.order.web;

import com.alipay.api.AlipayApiException;
import com.atguigu.gulimall.order.alipay.AlipayTemplate;
import com.atguigu.gulimall.order.alipay.PayVo;
import com.atguigu.gulimall.order.entity.OrderEntity;
import com.atguigu.gulimall.order.service.OrderService;
import com.atguigu.gulimall.order.vo.OrderSubmitRespVo;
import com.atguigu.gulimall.order.vo.OrderSubmitVo;
import com.atguigu.gulimall.order.vo.OrderVo;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import java.util.Date;
import java.util.UUID;

/**
 * @author 满超
 * @date 2020/06/26
 **/
@Controller
public class IndexController {

    @Autowired
    OrderService orderService;

    @Autowired
    AlipayTemplate alipayTemplate;


    @GetMapping("/{page}.html")
    public String page(@PathVariable("page") String page) {
        return page;
    }

    @GetMapping("/toTrade")
    public String jiesuan(Model model) {
        OrderVo orderVo = orderService.confirm();

        model.addAttribute("orderData", orderVo);
        return "jiesuan";
    }

    @PostMapping("/submitOrder")
    public String submitOrder(OrderSubmitVo submitVo, Model model){
        //完成下单操作
        OrderSubmitRespVo respVo = orderService.submit(submitVo);
        if (respVo.getCode() != 0) {
            //失败
            return "redirect:http://order.gulimall.com/toTrade";
        }
        model.addAttribute("orderResp",respVo);
        return "shouyin";
    }
}
